// 分派 assignment
export default {
	data() {
		return {
			// 分派案件
			assignmentLayer: {
				show: false,
				title: '案件分派',
				form: {
					idList: 0
				},
				caseType: 0
			},
			// 角色
			roleData: {
				list: [],
				form: {
					name: ''
				}
			},
			// 目标
			targetData: {
				list: [],
				form: {
					id: ''
				},
				active: true   // 30005:不需要选择审核人
			}
		}
	},
	computed: {},
	mounted() { },
	methods: {
		// 显示分派案件
		showAssignmentLayer(id, caseType) {
			this.assignmentLayer.show = true
			this.assignmentLayer.form = {}
			this.assignmentLayer.caseType = caseType
			this.assignmentLayer.form.idList = id
			this.clearRose()
			this.clearTarget()
			this.targetData.active = true
		},
		// 获取角色列表
		queryRoleList(type) {
			this.clearRose()
			this.clearTarget()
			api.queryCirculation({ type: type }).then((res) => {
				if (res.length == 0) {
					this.targetData.active = false
					this.$msg.error('没有权限分派该案件')
				}
				else {
					this.targetData.active = true
					this.roleData.list = res
				}
			}).catch(res => {
				if (res.data.code == '30005') {
					this.targetData.active = false
				}
			})
		},
		// 分派方式
		assignmentMethodChange(val) {
			this.clearRose()
			this.clearTarget()
			// 手动
			if (val == 1) {
				let _type = 2
				switch (this.assignmentLayer.caseType) {
					case 1:
						_type = 2
						break
					case 2:
						_type = 5
						break
					case 3:
						_type = 6
						break
				}
				this.queryRoleList(_type)
			}
			//自动
			else if (val == 2) {
				this.targetData.active = false
			}
		},
		// 选中角色
		roleChange(id) {
			this.clearTarget()
			api.queryRoleUserById({ id: id }).then(res => {
				this.targetData.list = res
			}).catch(res => {
				console.log(res)
			})
		},
		// 清空角色选项
		clearRose() {
			this.roleData.list = []
			this.roleData.form = {}
		},
		// 清空目标选项
		clearTarget() {
			this.targetData.list = []
			this.targetData.form = {}
		},
		// 提交分派案件
		assignmentCaseSave() {
			this.assignmentLayer.form.targetId = this.targetData.form.id
			api.allotSelectedCase(this.assignmentLayer.form).then(res => {
				this.$msg.success('案件分派成功')
				this.$store.dispatch('getUnProcess')
				this.tipsLayer.show = false
				this.assignmentLayer.show = false
				this.sumbitSave()
			}).catch(res => {
				console.log(res)
			})
		}
	}
}